package managment;

import java.util.ArrayList;
import java.util.Iterator;


@SuppressWarnings("unchecked")
public abstract class ArraySource {

	protected ArrayList <Comparable[]> product;
	
	public void removeFromList(int index){
		product.remove(index);
	}
	
	public Comparable[] getFromList(int index){
		return product.get(index);
	}
	
	protected ArraySource(int maxArraySize, Object prmtr){
	    
	    if(this.product==null){
		this.product=new ArrayList<Comparable[]>();	
	    }
	}
	
	public static ArraySource getSuitableInstance(InType inFlag, int size, Object obj)
	throws MyException{

	    switch(inFlag){
		
		case auto:
			return new Auto(size, obj);
			
		case file:
			return new External(size, obj);
		default:
			break;
		}
		
		return null;
	}
	
	abstract public ArrayList<Comparable[]> createTarget() throws MyException;
		
	public abstract class MyException extends Exception{
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		String msg;
		protected MyException(String msg){
			this.msg=msg;
		}
		abstract public void handle();
	} 
	public int getListSize(){
	    if(this.product!=null)
		return this.product.size();
	    else
		return 0;
	}
	
	public void printTarget(){
		Iterator <Comparable[]> iter=this.product.iterator();
		while(iter.hasNext()){
			Comparable[] temp=iter.next();
			for (int i = 0; i < temp.length; i++) {
				System.out.print((Integer)temp[i]+", ");
			}
			System.out.println();
		}
	}
}